package com.zmn.oms.task.listener;

import com.jd.open.api.sdk.internal.JSON.JSON;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.oms.manager.utils.OmsMqTagConsts;
import com.zmn.oms.zmn.normal.business.interfaces.work.OrderLifeCycleBService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author sunlife
 * @date:2021/1/27 3:33 下午
 * description:
 */
@AliyunMQListener(topic = "${spring.mq.topic.performance}")
@Component
public class OrderLiftCycleListener {

    private Logger logger = LoggerFactory.getLogger(OrderLiftCycleListener.class);

    private static final String TAG_NAME = "LEFT_ORDER_NOTICE";

    @Autowired
    OrderLifeCycleBService orderLifeCycleBService;


    @AliyunMQHandler(tags = TAG_NAME)
    public void process(String message) {
        logger.info("生命周期工单预警处理信息：{}", message);
        try {
            List<Long> workIds = com.alibaba.fastjson.JSON.parseArray(message, Long.class);
            if (CollectionUtil.isNullOrEmpty(workIds)) {
                return;
            }
            orderLifeCycleBService.processExpiredOrderWorks(workIds);

        } catch (Exception e) {
            logger.error(String.format("生命周期预警工单处理失败：%s", message), e);
        }

    }
}
